package com.xzwzz.leetcode

import com.sun.tools.corba.se.idl.StringGen

object LeetCodeCache {
    @JvmStatic
    fun main(args: Array<String>) {
        print((reverseString(arrayOf('h','e','l','l','o'))))
    }

    fun reverseString(s: Array<Char>): CharArray {
        if (s.size == 0) {
            return s.toCharArray()
        }
        val length = s.size
        return if (length == 1) {
            s.toCharArray()
        } else {
            reverseString(s.sliceArray(1..s.lastIndex)) + charArrayOf(s[0])
        }
    }

    fun twoSum(nums: IntArray, target: Int): IntArray {
        val map = hashMapOf<Int, Int>()

        nums.forEachIndexed { index, value ->
            if (map.containsKey(target - value)) {
                return map.values.toIntArray()
            }
            map.put(value, index)
        }

        return map.keys.toIntArray()
    }
}